package com.aube.interact.fighter;

import android.content.Context;
import android.util.Log;
import android.widget.RelativeLayout;

import com.aube.interact.fighter.card.BaseCardNew;
import com.aube.interact.fighter.card.CardGuess;
import com.aube.interact.fighter.card.CardInfo;
import com.aube.interact.fighter.card.CardInfoThumb;
import com.aube.interact.fighter.card.CardQA;
import com.aube.interact.fighter.card.CardVS;
import com.aube.interact.fighter.card.CardVote;
import com.aube.interact.fighter.control.DataManager;
import com.aube.interact.fighter.model.TimeLinePiece;
import com.huyn.baseframework.model.ChannelDetail;
import com.huyn.baseframework.utils.StringUtils;

/**
 * Created by hill on 10/24.
 */
public class ViewGenerator {

    public static BaseCardNew getView(TimeLinePiece data, ChannelDetail channelDetail, Context context) {
        Log.e("ViewGenerator", "getView: data.type = " + data.type);
        String type = data.type;
        BaseCardNew card = null;
        if (TimeLinePiece.TYPE_VOTE.equalsIgnoreCase(type)) {
            Log.e("ViewGenerator", "getView : Vote");
            card = new CardVote(context);
        } else if (TimeLinePiece.TYPE_VS.equalsIgnoreCase(type)) {
            Log.e("ViewGenerator", "getView : VS");
            card = new CardVS(context);
        } else if (TimeLinePiece.TYPE_QA.equalsIgnoreCase(type)) {
            Log.e("ViewGenerator", "getView : QA");
            card = new CardQA(context);
        } else if (TimeLinePiece.TYPE_INFO.equalsIgnoreCase(type)) {
            Log.e("ViewGenerator", "getView : INFO");
            if(data.showInfoDetail)
                card = new CardInfo(context);
            else
                card = new CardInfoThumb(context);
        } else if (TimeLinePiece.TYPE_QUIZ.equalsIgnoreCase(type)) {
            Log.e("ViewGenerator", "getView : QUIZ");
            //判断是否应该展示卡片,如果之前没有选过,就返回空
            int selectedIndex = DataManager.getInstance(context).getIndex(data.getRid());
            if(selectedIndex < 0 && data.showQuizResult)
                return null;
            card = new CardGuess(context);
        }

        if(card != null)
            card.init(data, channelDetail);
        return card;
    }

    public static void generateParamsStyle(RelativeLayout.LayoutParams params, int relativeMode) {
        switch (relativeMode) {
            case 0://居中
                params.addRule(RelativeLayout.CENTER_IN_PARENT);
                break;
            case 1://上左
                params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
                params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
                break;
            case 2://上中
                params.addRule(RelativeLayout.CENTER_HORIZONTAL);
                break;
            case 3://上右
                params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
                break;
            case 4://靠右 | 垂直居中
                params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
                params.addRule(RelativeLayout.CENTER_VERTICAL);
                break;
            case 5://下右
                params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
                params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
                break;
            case 6://下中
                params.addRule(RelativeLayout.CENTER_HORIZONTAL);
                params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
                break;
            case 7://下左
                params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
                break;
            case 8://靠左 | 水平居中
                params.addRule(RelativeLayout.CENTER_VERTICAL);
                break;
        }
    }

}
